<?php
namespace app\member\model;

use think\Model;

class Base extends Model
{
    /**
     * 构造函数，用于这是Logic层的表前缀
     * @param string $name 模型名称 $tablePrefix 表前缀    $connection 数据库连接信息
     */
    public function __construct($name = '', $tablePrefix = '', $connection = '')
    {
        /* 设置默认的表前缀 */
        $this->tablePrefix = C('DB_PREFIX') . 'wechat_';
        /* 执行构造方法 */
        parent::__construct($name, $tablePrefix, $connection);
    }

    public function dataUpdate($data)
    {
        if (!$data['id']) {
            $res = $this->allowField(true)->insert($data);
            if ($res) {
                return array('ret' => 1, 'msg' => '添加成功');
            } else {
                return array('ret' => 0, 'msg' => '添加失败');
            }
        } else {
            $res = $this->allowField(true)->update($data);
            //$res = db(\tname::weixin_keywords)->field('name')->update($data);
            if ($res) {
                return array('ret' => 1, 'msg' => '修改成功');
            } else {
                return array('ret' => 0, 'msg' => '修改失败');
            }
        }
    }

}
